package com.liang.blog.common.exception;

import com.liang.blog.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author：YanWenLiang
 * @Date:2023-05-23-16:21
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        System.out.println("全局异常管理");
        return Result.fail();
    }

    /**
     * 自定义异常处理方法
     * @param e
     * @return
     */
    @ExceptionHandler(BlogException.class)
    @ResponseBody
    public Result error(BlogException e){
        e.printStackTrace();
        return Result.build(e.getCode(), e.getMessage());
    }
}

